<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head th:replace="/common/include :: header(~{::title}, ~{::link}, ~{::style})">
    <title>客户端管理-应用授权管理-编辑</title>
</head>
<body class="white-bg">
<form class="form-horizontal m" id="form-edit">
    <div class="animated fadeInRight form-content">
        <input type="hidden" id="autoapprove" name="autoapprove" value="true"/>
        <input type="hidden" id="accessTokenValidity" name="accessTokenValidity" value="7200"/>
        <div class="form-group">
            <label class="col-sm-3 control-label">Client ID：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="clientId" id="clientId"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">租户名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="clientName" id="clientName"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label" title="请使用英文逗号分割">资源限定串：<i class="fa fa-question-circle-o"></i></label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="resourceIds" id="resourceIds"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">密钥：</label>
            <div class="col-sm-8">
                <input class="form-control" type="password" name="clientSecretStr" id="clientSecretStr"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">范围：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="scope" id="scope"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">授权方式：</label>
            <div class="col-sm-8">
                <div class="check-box" style="width: 150px;" th:each="config : ${@dict.getAuthorizedGrantTypes()}">
                    <input type="checkbox" th:id="${config.value}" name="authorizedGrantTypes" th:value="${config.value}"/>
                    <label th:for="${config.value}" th:text="${config.name}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">回调地址：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="webServerRedirectUri" id="webServerRedirectUri"/>
            </div>
        </div>
    </div>

    <div class="form-footer sticky">
        <button type="button" class="btn btn-success form-submit" th:classappend="${@config.hasPermission('client:oauth:edit')}" onclick="save()">保存</button>
        <button type="button" class="btn btn-default" onclick="closeWin()">关闭</button>
    </div>
</form>

<div th:replace="/common/include :: footer"></div>

<script th:inline="javascript">
    var id = [[${id}]];
    var layer_index = [[${layer_index}]];
    var layer_callback = [[${layer_callback}]];
    var permitted = [[${@config.isPermittedOperator('system:oauth:add')}]];
    var prefix = ctx + 'api/oauth';

    $(function () {
        // 表单赋值
        $.operate.get({
            url: prefix + '/load',
            data: {
                'id': id
            },
            success: function(result) {
                if (result.code === 200) {
                    $.form.load('form-edit', result.param, !permitted);
                    $.form.initValidatorRemote('form-edit', 'oauth_client_details');
                } else {
                    $.modal.toast.error(result.msg, result.param);
                    setTimeout(function () {
                        window.location.href = ctx + 'error/' + result.code;
                    }, 1500);
                }
            },
            error: function(result) {
                window.location.href = ctx + 'error/500';
            }
        });
    });

    function save() {
        if ($.form.isValid('form-edit')) {
            // 加载参数数据
            var param = $.form.serialize('form-edit');
            $.operate.post({
                url: prefix + '/save',
                data: param
            }, true, layer_index, layer_callback);
        }
    }

    function closeWin() {
        $.modal.lay.close();
    }
</script>
</body>
</html>
